package com.jch.wns.util;

import com.alibaba.fastjson.JSON;
import com.jch.wns.domain.MsgServerProtocol;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

public class MsgUtil {

    public static TextWebSocketFrame buildMsgAll(String channelId,String msgInfo) {
        int i = Math.abs(channelId.hashCode()) % 10; // 模拟头像
        MsgServerProtocol msg = new MsgServerProtocol();
        msg.setType(2); // 1 自发信息、2 群发信息
        msg.setChannelId(channelId);
        msg.setUserHeadImg("head" + i + ".jpg");
        msg.setMsgInfo(msgInfo);
        return new TextWebSocketFrame(JSON.toJSONString(msg));
    }

    public static TextWebSocketFrame buildMsgOwner(String channelId){
        MsgServerProtocol msg = new MsgServerProtocol();
        msg.setType(1);
        msg.setChannelId(channelId);
        return new TextWebSocketFrame(JSON.toJSONString(msg));
    }
}
